<template>
  <div class="contioner" v-loading="pageData.loadingUp">
    <a-tabs :lazy-load="true" justify @change="tabChange" :default-active-key="pageData.active">
      <a-tab-pane key="1" title="报废申请">
        <pageTabelLayout>
          <template #pageHeader>
            <div class="my-tool-bar" style="margin-bottom: 5px">
              <a-space>
                <el-button type="primary" :icon="Search" @click="getList">查询</el-button>
                <el-button type="success" :icon="CirclePlus" @click="newData('新增')"
                  >新增</el-button
                >
                <el-button :icon="EditPen" @click="audit">审核</el-button>
                <el-button plain @click="TurnDown">驳回</el-button>
                <el-button plain :icon="Delete" @click="deleteData">删除</el-button>
              </a-space>
            </div>
          </template>
          <!-- <div style="background-color: #f0f2f5; height: 10px"></div> -->
          <template #pageTabel>
            <encapsulation-agrid
              ref="refgridOption"
              :configaggrid="configaggrid"
            ></encapsulation-agrid>
          </template>
        </pageTabelLayout>
      </a-tab-pane>
      <a-tab-pane key="2" title="报废待处理">
        <pageTabelLayout>
          <template #pageHeader>
            <div class="search-form isheader" v-show="pageData.headerShow">
              <a-form size="small" :model="query" layout="inline">
                <CorporateSectorCascader
                  :style="{ width: '200px' }"
                  :configCascader="configCascader"
                  @changeCascader="changeCascader"
                  v-if="pageData.active1 == 1"
                />
                <CorporateSectorCascader
                  :style="{ width: '200px' }"
                  :configCascader="configCascader4"
                  @changeCascader="changeCascader4"
                  v-if="pageData.active1 == 2"
                />
                <a-form-item label="报废人">
                  <a-input
                    allow-clear
                    :style="{ width: '180px' }"
                    class="bacClass"
                    v-model="pageData.scrapPerson"
                  />
                </a-form-item>
                <a-form-item label="报废单号">
                  <a-input
                    allow-clear
                    :style="{ width: '180px' }"
                    class="bacClass"
                    v-model="pageData.scrapCode"
                  />
                </a-form-item>
              </a-form>
            </div>
            <div class="my-divisders">
              <a-divider orientation="center">
                <icon-double-up
                  v-if="pageData.headerShow"
                  @click="pageData.headerShow = false"
                  :strokeWidth="2"
                  :size="18"
                />
                <icon-double-down
                  v-else
                  @click="pageData.headerShow = true"
                  :strokeWidth="2"
                  :size="18"
                />
              </a-divider>
            </div>
            <div class="my-tool-bar">
              <a-space>
                <el-button type="primary" :icon="Search" @click="getList">查询</el-button>
                <el-button :icon="EditPen" @click="scrapDisposal">报废处理</el-button>
              </a-space>
            </div>
          </template>
          <template #pageTabel>
            <a-tabs
              :lazy-load="true"
              justify
              @change="tabChange1"
              :default-active-key="pageData.active1"
            >
              <a-tab-pane key="1" title="固定资产">
                <encapsulation-agrid
                  ref="refgridOption1"
                  :configaggrid="configaggrid1"
                ></encapsulation-agrid>
              </a-tab-pane>
              <a-tab-pane key="2" title="非固定资产">
                <encapsulation-agrid
                  ref="refgridOption6"
                  :configaggrid="configaggrid6"
                ></encapsulation-agrid>
              </a-tab-pane>
            </a-tabs>
          </template>
        </pageTabelLayout>
      </a-tab-pane>
      <a-tab-pane key="3" title="报废已处理">
        <pageTabelLayout>
          <template #pageHeader>
            <div class="search-form isheader" v-show="pageData.headerShow1">
              <a-form size="small" :model="query" layout="inline">
                <CorporateSectorCascader
                  :style="{ width: '200px' }"
                  :configCascader="configCascader1"
                  @changeCascader="changeCascader1"
                />
                <a-form-item label="开始时间" field="startDate">
                  <a-date-picker
                    popup-container="html"
                    :style="{ width: '200px' }"
                    class="bacClass"
                    v-model="pageData.startDate"
                    @press-enter="huiche"
                  />
                </a-form-item>
                <a-form-item label="结束时间" field="endDate">
                  <a-date-picker
                    popup-container="html"
                    :style="{ width: '200px' }"
                    class="bacClass"
                    v-model="pageData.endDate"
                    @press-enter="huiche"
                  />
                </a-form-item>
              </a-form>
            </div>
            <div class="my-divisders">
              <a-divider orientation="center">
                <icon-double-up
                  v-if="pageData.headerShow1"
                  @click="pageData.headerShow1 = false"
                  :strokeWidth="2"
                  :size="18"
                />
                <icon-double-down
                  v-else
                  @click="pageData.headerShow1 = true"
                  :strokeWidth="2"
                  :size="18"
                />
              </a-divider>
            </div>
            <div class="my-tool-bar">
              <a-space>
                <el-button type="primary" :icon="Search" @click="getList">查询</el-button>
              </a-space>
            </div>
          </template>
          <template #pageTabel>
            <a-tabs
              :lazy-load="true"
              justify
              @change="tabChange2"
              :default-active-key="pageData.active2"
            >
              <a-tab-pane key="1" title="固定资产">
                <encapsulation-agrid
                  ref="refgridOption2"
                  :configaggrid="configaggrid2"
                ></encapsulation-agrid>
              </a-tab-pane>
              <a-tab-pane key="2" title="非固定资产">
                <encapsulation-agrid
                  ref="table3Ref"
                  :configaggrid="configTable3"
                ></encapsulation-agrid>
              </a-tab-pane>
            </a-tabs>
          </template>
        </pageTabelLayout>
      </a-tab-pane>
    </a-tabs>

    <a-drawer
      cancel-text="关闭"
      ok-text="保存"
      popup-container=".arco-tabs-content"
      height="91vh"
      placement="bottom"
      :visible="pageData.showAdd"
      unmountOnClose
      @cancel="pageData.showAdd = false"
      @ok="confirmSave"
      :mask-closable="false"
    >
      <template #title> {{ pageData.type }}</template>
      <div class="darCont" v-loading="loadingUp2">
        <el-form
          ref="ruleFormRef"
          :model="query"
          class="demo-query"
          status-icon
          label-width="auto"
          label-position="Right"
        >
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item
                label="报废单号"
                prop="scrapCode"
                :rules="[{ required: true, message: '报废单号必选' }]"
              >
                <el-input v-model="query.scrapCode" style="width: 200px" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="12" style="display: flex">
              <!-- <el-form-item label="报废公司" prop="companyName">
                <el-input v-model="query.companyName" style="width: 200px" disabled />
              </el-form-item> -->
              <CorporateSectorCascader
                ref="cascaderRef3"
                :configCascader="configCascader3"
                @changeCascader="changeCascader3"
              />
            </el-col>
            <!-- <el-col :span="6">
              <el-form-item label="报废部门" prop="departmentName">
                <el-input v-model="query.departmentName" style="width: 200px" disabled />
              </el-form-item>
            </el-col> -->
            <el-col :span="6">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="query.remark" style="width: 200px" />
              </el-form-item>
            </el-col>
            <!-- <el-col :span="6">
              <el-form-item label="是否固定资产类" prop="fixedAsset">
                <el-radio-group v-model="pageData.fixedAsset">
                  <el-radio :label="true" border>是</el-radio>
                  <el-radio :label="false" border>否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col> -->
          </el-row>
        </el-form>
        <!-- <div class="hengxian"></div> -->
        <el-button
          v-if="pageData.fixedAsset"
          style="margin-left: 15px"
          :icon="CirclePlus"
          @click="addWorkbench"
          type="success"
          >选择固资</el-button
        >

        <el-button
          v-else
          style="margin-left: 15px"
          :icon="CirclePlus"
          @click="addWorkbench"
          type="success"
          >选择物料</el-button
        >

        <el-button style="margin-left: 30px" :icon="Delete" @click="deleteWorkbench" type="warning"
          >删除</el-button
        >
        <div
          :style="{ height: '82%', padding: '10px' }"
          style="background: #fff"
          v-show="pageData.fixedAsset"
        >
          <encapsulation-agrid
            ref="refgridTheyAreFixedAssetsAggrid"
            :configaggrid="TheyAreFixedAssetsAggrid"
          ></encapsulation-agrid>
        </div>
        <div
          :style="{ height: '82%', padding: '10px' }"
          style="background: #fff"
          v-show="!pageData.fixedAsset"
        >
          <encapsulation-agrid
            ref="refgridNoFixedAssets"
            :configaggrid="NoFixedAssetsAggrid"
          ></encapsulation-agrid>
        </div>
      </div>
    </a-drawer>

    <a-drawer
      cancel-text="关闭"
      ok-text="保存"
      popup-container=".arco-tabs-content"
      height="91vh"
      placement="bottom"
      :visible="pageData.showAdd1"
      unmountOnClose
      @cancel="pageData.showAdd1 = false"
      @ok="scrapMode"
      :mask-closable="false"
    >
      <template #title> 选择报废方式</template>
      <div
        :style="{ height: '90%', padding: '10px' }"
        v-loading="loadingUp1"
        v-if="pageData.active1 == 1"
      >
        <encapsulation-agrid
          ref="refgridOption3"
          :configaggrid="configaggrid3"
        ></encapsulation-agrid>
      </div>
      <div :style="{ height: '90%', padding: '10px' }" v-loading="loadingUp1" v-else>
        <encapsulation-agrid ref="table2Ref" :configaggrid="configTable2"></encapsulation-agrid>
      </div>
    </a-drawer>
    <a-drawer
      cancel-text="关闭"
      ok-text="保存"
      popup-container=".arco-tabs-content"
      height="91vh"
      placement="bottom"
      :visible="pageData.workbenchShowAdd"
      unmountOnClose
      @cancel="pageData.workbenchShowAdd = false"
      @ok="stockKeeping"
      :mask-closable="false"
      style="z-index: 999"
    >
      <template #title> 选择物料 </template>
      <div style="width: 100%; height: 95%">
        <el-form
          :model="query"
          class="demo-query"
          status-icon
          label-width="auto"
          label-position="Right"
          style="margin-bottom: 20px"
        >
          <el-row :gutter="24" v-show="pageData.fixedAsset">
            <!-- <el-col :span="6">
              <el-form-item label="厂区" prop="companyID">
                <el-select-v2 v-model="TheyAreFixedAssets.companyId" :options="seclectList.factoryList" placeholder="选择厂区"
                  filterable :loading="pageData.loadingUp" clearable size="default" />
              </el-form-item>
            </el-col> -->
            <el-col :span="6">
              <el-form-item label="物料名称" prop="materialName">
                <!-- <el-select-v2 v-model="TheyAreFixedAssets.mechanicalName" :options="seclectList.mechanicalNameList"
                  placeholder="选择物料名称" filterable :loading="pageData.loadingUp" clearable size="default" /> -->
                <el-input v-model="TheyAreFixedAssets.materialName" placeholder="输入物料名称" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="物料编号" prop="materialCode">
                <!-- <el-select-v2 v-model="TheyAreFixedAssets.mechanicalName" :options="seclectList.mechanicalNameList"
                  placeholder="选择物料名称" filterable :loading="pageData.loadingUp" clearable size="default" /> -->
                <el-input v-model="TheyAreFixedAssets.materialCode" placeholder="输入物料编号" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="固定资产编码" prop="numberId">
                <!-- <el-select-v2 v-model="TheyAreFixedAssets.numberId" :options="seclectList.mechanicalCodeList"
                  placeholder="选择固定资产编码" filterable :loading="pageData.loadingUp" clearable size="default" /> -->
                <el-input v-model="TheyAreFixedAssets.numberId" placeholder="输入固定资产编码" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属区域" prop="district">
                <!-- <el-select-v2 v-model="TheyAreFixedAssets.district" :options="seclectList.districtList"
                  placeholder="选择所属区域" filterable :loading="pageData.loadingUp" clearable size="default" /> -->
                <el-input v-model="TheyAreFixedAssets.district" placeholder="输入所属区域" />
              </el-form-item>
            </el-col>
            <!-- <el-col :span="6">
              <el-form-item label="开始时间" prop="startDate">
                <el-date-picker v-model="TheyAreFixedAssets.startDate" type="date" placeholder="选择开始时间"
                  format="YYYY-MM-DD" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="结束时间" prop="endDate">
                <el-date-picker v-model="TheyAreFixedAssets.endDate" type="date" placeholder="选择结束时间"
                  format="YYYY-MM-DD" />
              </el-form-item>
            </el-col> -->

            <el-col
              :span="24"
              style="display: flex; justify-content: flex-end; align-items: center"
            >
              <el-button type="primary" :icon="Search" @click="FixedAssetsgetList">查询</el-button>
            </el-col>
          </el-row>
          <el-row :gutter="24" v-show="!pageData.fixedAsset">
            <el-col :span="6">
              <el-form-item label="物料大类" prop="bigClassName">
                <el-select-v2
                  v-model="NoFixedAssets.bigClassName"
                  :options="seclectList.MaterialCategoryList"
                  placeholder="选择物料大类"
                  filterable
                  :loading="pageData.loadingUp"
                  clearable
                  size="default"
                />
                <!-- @change="MaterialCategorSelect" -->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="物料小类" prop="mechanicalName">
                <el-select-v2
                  v-model="NoFixedAssets.subClassName"
                  :options="seclectList.MaterialsubclassList"
                  placeholder="选择物料小类"
                  filterable
                  :loading="pageData.loadingUp"
                  clearable
                  size="default"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="物料名称" prop="mechanicalName">
                <el-select-v2
                  v-model="NoFixedAssets.mechanicalName"
                  :options="seclectList.MaterialNameList"
                  placeholder="选择物料名称"
                  filterable
                  :loading="pageData.loadingUp"
                  clearable
                  size="default"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="物料编号" prop="district">
                <el-select-v2
                  v-model="NoFixedAssets.district"
                  :options="seclectList.MaterialNumberList"
                  placeholder="选择物料编号"
                  filterable
                  :loading="pageData.loadingUp"
                  clearable
                  size="default"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="规格" prop="specName">
                <el-select-v2
                  v-model="NoFixedAssets.specName"
                  :options="seclectList.SpecificationsList"
                  placeholder="选择规格"
                  filterable
                  :loading="pageData.loadingUp"
                  clearable
                  size="default"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6"></el-col>
            <el-col :span="6"></el-col>
            <el-col :span="6" style="display: flex; justify-content: center; align-items: center">
              <el-button type="primary" :icon="Search" @click="FixedAssetsgetList">查询</el-button>
            </el-col>
          </el-row>
        </el-form>
        <div
          :style="{ height: '90%', padding: '10px' }"
          style="background: #fff"
          v-show="pageData.fixedAsset"
        >
          <encapsulation-agrid
            ref="refgridOption4"
            :configaggrid="configaggrid4"
            @SelectionChanged="selectionChange"
          ></encapsulation-agrid>
        </div>
        <div
          :style="{ height: '90%', padding: '10px' }"
          style="background: #fff"
          v-show="!pageData.fixedAsset"
        >
          <encapsulation-agrid
            ref="refgridOption5"
            :configaggrid="configaggrid5"
          ></encapsulation-agrid>
        </div>
      </div>
    </a-drawer>
    <el-dialog
      align-center
      style="width: 1200px; height: 450px"
      v-model="pageData.dialogFormVules"
      v-loading="loadingElplus"
    >
      <!-- <div style="width: 100%; height: 450px"> -->
      <AgGridVuesCopys
        v-if="pageData.active1 == 1 || pageData.active2 == 1"
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        rowSelection="multiple"
        @grid-ready="gridReady"
        style="height: 37vh"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="pageData.dataListOP"
        :columnDefs="pageData.dataListTable"
        :localeText="localeText1"
      >
      </AgGridVuesCopys>
      <div style="width: 100%; height: 37vh" v-if="pageData.active1 == 2">
        <encapsulation-agrid ref="table1Ref" :configaggrid="configTable1"></encapsulation-agrid>
      </div>
      <!-- </div> -->
    </el-dialog>
    <el-dialog
      align-center
      style="width: 1200px; height: 450px"
      v-model="pageData.dialogFormVules1"
      v-loading="loadingElplus"
    >
      <div style="width: 100%; height: 37vh">
        <encapsulation-agrid ref="table4Ref" :configaggrid="configTable4"></encapsulation-agrid>
      </div>
      <!-- </div> -->
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
  // 引入element提示
  import { ElMessage, ElMessageBox } from 'element-plus'
  
  import { localeText } from '@/api/aggridZw'
  //引入封装post
  import { post } from '@/api/http'
  import {
    tableColumns,
    tableColumns1,
    tableColumns2,
    // tableColumns3,
    tableColumns4,
    tableColumns5,
    tableColumns6,
    tableColumns7,
    tableColumns10,
  } from './RetirementOfFixedAssets'
  import buttionRender from '@/components/aggridCellRenDerer/buttionRender.vue'
  import CorporateSectorCascader from '@/components/corporateSectorCascader1/index.vue'
  import { Search, Delete, CirclePlus, EditPen, Download } from '@element-plus/icons-vue'
  import { ITEM } from 'gantt-schedule-timeline-calendar/dist/plugins/timeline-pointer.esm.min'
  import selectRender from '@/components/aggridCellRenDerer/selectRender.vue'
  import tagRender from '@/components/aggridCellRenDerer/tagRender.vue'
  import emitter from '@/hooks/useEventBus'
  let pageData = reactive<any>({
    showAdd: false,
    showAdd1: false,
    workbenchShowAdd: false,
    type: '',
    loadingUp: false,
    loadingUp1: false,
    loadingUp2: false,
    active: '1',
    active1: '1',
    active2: '1',
    headerShow: true,
    id: '',
    companyID: '',
    companyName: '',
    companyID1: '',
    companyName1: '',
    mechanicalCode: '',
    scrapCode: '',
    scrapPerson: '',
    headerShow1: true,
    startDate: '',
    endDate: '',
    fixedAsset: '',
    dialogFormVules: false,
    dialogFormVules1: false,
    dataListOP: [],
    dataListTable: [],
  })
  const table1Ref = ref<any>(null)
  const tabChange1 = (val: any) => {
    pageData.active1 = val
    if (val == 1) {
      let pam = { ...form }
      pam.scrapCode = pageData.scrapCode
      pam.scrapPerson = pageData.scrapPerson
      // pam.companyName = pageData.companyName
      pam.companyID = pageData.companyID
      pam.departmentName = pageData.departmentName
      pam.departmentID = pageData.departmentID
      pam.deleteState = 0
      pam.auditState = 1
      pam.processedState = 0
      nextTick(() => {
        refgridOption1.value.setQuery(pam)
      })
    } else if (val == 2) {
      // let mockData = [
      //   {
      //     departmentName: ' 织造一厂',
      //     companyName: '织造一厂',
      //     departmentID: 666,
      //     fixAssetStatus: 0,
      //     updateTime: '2024-05-16 15:54:54',
      //     updateName: 'zpf',
      //     auditState: 1,
      //     companyID: 32,
      //     createTime: '2024-03-13 10:55:39',
      //     scrapPerson: 'zpf',
      //     scrapCode: 'BF24031301',
      //     id: 173,
      //     createName: 'zpf',
      //   },
      // ]
      let params = { ...form }
      params.scrapCode = pageData.scrapCode
      params.createName = pageData.scrapPerson
      params.companyID = pageData.companyID
      nextTick(() => {
        refgridOption6.value.setQuery(params)
      })
    }
  }
  const table3Ref = ref<any>(null)
  const tabChange2 = (val: any) => {
    pageData.active2 = val
    if (val == 1) {
      nextTick(() => {
        refgridOption2.value.setQuery({ deleteState: 0, processedState: 1 })
      })
    } else if (val == 2) {
      nextTick(() => {
        table3Ref.value.setQuery({
          companyID: pageData.companyID1,
          processedState: '1',
          startTime: pageData.startDate,
          endTime: pageData.endDate,
        })
      })
    }
  }
  let query = reactive<any>({
    scrapCode: '',
    companyID: '',
    companyName: '',
    district: '',
    mechanicalName: '',
    mechanicalCode: '',
    joinFactoryTime: '',
    scrapTime: '',
    deprecitionTime: '',
    difference: '',
    departmentID: '',
    departmentName: '',
    remark: '',
  })
  const TheyAreFixedAssets = reactive<any>({
    companyId: '',
    mechanicalName: '',
    numberId: '',
    district: '',
    startDate: '',
    endDate: '',
    outFirmId: query.companyID,
    outDepartmentId: query.departmentID,
  })
  // 否规定资产
  const NoFixedAssets = reactive<any>({
    bigClassName: '',
    subClassName: '',
    mechanicalName: '',
    district: '',
    specName: '',
  })
  const gridOption = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
  }
  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }
  const loadingElplus = ref(false)
  const localeText1: any = ref(localeText)
  tableColumns.push({
    headerName: '操作',
    field: 'ouihadpc',
    resizable: 'false',
    filter: false,
    sortable: 'false',
    width: 200,
    // lockPosition: 'right',
    pinned: 'right',
    cellRenderer: buttionRender,
    cellRendererParams: {
      buttonList: [
        {
          type: 'success',
          text: '修改',
          typeName: 'el-button',
          Callback: (data: any) => {
            for (let key in data) {
              query[key] = data[key]
            }
            newData('修改', data)
          },
        },
        {
          type: 'success',
          text: '详情',
          typeName: 'el-button',
          Callback: (data: any) => {
            for (let key in data) {
              query[key] = data[key]
            }
            newData('详情', data)
          },
        },
      ],
      eltagSize: 0,
    },
  })
  tableColumns1.push({
    headerName: '操作',
    field: 'ouihadpc',
    resizable: 'false',
    filter: false,
    sortable: 'false',
    width: 120,
    // lockPosition: 'right',
    pinned: 'right',
    cellRenderer: buttionRender,
    cellRendererParams: {
      buttonList: [
        {
          type: 'success',
          text: '详情',
          typeName: 'el-button',
          Callback: (data: any) => {
            for (let key in data) {
              query[key] = data[key]
            }
            newData('详情', data)
          },
        },
      ],
      eltagSize: 0,
    },
  })
  tableColumns2.push({
    headerName: '操作',
    field: 'ouihadpc',
    resizable: 'false',
    filter: false,
    sortable: 'false',
    width: 120,
    // lockPosition: 'right',
    pinned: 'right',
    cellRenderer: buttionRender,
    cellRendererParams: {
      buttonList: [
        {
          type: 'success',
          text: '详情',
          typeName: 'el-button',
          Callback: (data: any) => {
            for (let key in data) {
              query[key] = data[key]
            }
            newData('详情', data)
          },
        },
      ],
      eltagSize: 0,
    },
  })

  let refgridOption = ref<any>()
  let refgridOption1 = ref<any>()
  let refgridOption2 = ref<any>()
  let refgridOption3 = ref<any>()
  let refgridOption4 = ref<any>()
  let refgridOption5 = ref<any>()
  let refgridTheyAreFixedAssetsAggrid = ref<any>()
  let refgridNoFixedAssets = ref<any>()
  let configaggrid = ref({
    url: 'purchase/FixedScrap/getPage', //接口路径
    queryData: {
      deleteState: 0,
      auditState: 0,
      processedState: 0,
    },
    paginationShow: true, //分页是否显示
    invokeiIterface: true, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns,
    fileName: 'RetirementOfFixedAssets-1',
  })
  let tableColumns8: any = [
    {
      headerCheckboxSelection: true,
      checkboxSelection: true,
      width: 60,
      showDisabledCheckboxes: false,
      pinned: 'left',
    },
    {
      headerName: '物料大类',
      field: 'bigClassName',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleClassName',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subClassName',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 200,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 200,
    },
    // {
    //   headerName: '所属区域',
    //   field: 'district',
    //   width: 200,
    // },
    {
      headerName: '报废方式',
      field: 'scrapType',
      width: 200,
      // editable: true, // 覆盖了默认的不可编辑设置
      cellRenderer: selectRender,
      editable: true, // 覆盖了默认的不可编辑设置
      cellRendererParams: {
        changeData: (data: any) => {
          data.scrapMoney = 0
          const listData = JSON.parse(JSON.stringify(refgridOption3.value.getListData()))
          nextTick(() => {
            refgridOption3.value.setdataListIterface(listData)
          })
        },
        list: [
          { label: '有价值报废', value: '有价值报废' },
          { label: '无价值报废', value: '无价值报废' },
        ],
        key: 'scrapWay',
      },
    },
    {
      headerName: '报废金额',
      field: 'scrapMoney',
      width: 200,
      editable: (res: any) => {
        console.log(res)
        console.log(8888)
        return res.data.scrapWay == '有价值报废' ? true : false
      }, // 覆盖了默认的不可编辑设置
    },
    // {
    //   headerName: '购入金额',
    //   field: 'joinMoney',
    //   width: 200,
    // },
    // {
    //   headerName: '建立人',
    //   field: 'createName',
    //   width: 200,
    // },
    // {
    //   headerName: '创建时间',
    //   field: 'createTime',
    //   width: 200,
    // },
    // {
    //   headerName: '修改人',
    //   field: 'updateName',
    //   width: 200,
    // },
    // {
    //   headerName: '修改时间',
    //   field: 'updateTime',
    //   width: 200,
    // },
    // {
    //   headerName: '备注',
    //   field: 'remark',
    //   width: 200,
    // },
    {
      headerName: '处理状态',
      field: 'processedState',
      width: 200,
      cellRenderer: tagRender,
      cellRendererParams: {
        styleClass: (params: any) => {
          return params.processedState == 0
            ? 'warning'
            : params.processedState == 1
            ? 'success'
            : ''
        },
        text: (params: any) => {
          return params.processedState == 0 ? '未处理' : params.processedState == 1 ? '已处理' : ''
        },
        eltagSize: 0,
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '未处理' : params.value == '1' ? '已处理' : ''
        },
      },
    },
  ]
  const table2Ref = ref<any>(null)
  let configTable2 = ref({
    url: '', //接口路径
    queryData: {
      // deleteState: 0,
      // auditState: 0,
      // processedState: 0,
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns8,
    fileName: 'RetirementOfFixedAssets-8',
  })
  let configTable1 = ref({
    url: '', //接口路径
    queryData: {
      deleteState: 0,
      auditState: 0,
      processedState: 0,
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns7,
    fileName: 'RetirementOfFixedAssets-7',
  })
  const isRowSelectable = (rowNode: any) => {
    console.log(rowNode.data.machineState, rowNode.data.subCategory)

    if (
      rowNode.data.machineState != 0 &&
      (rowNode.data.subCategory === '单面机' ||
        rowNode.data.subCategory === '双面机' ||
        rowNode.data.subCategory === '罗纹机')
    ) {
      return false
    }
    return true
  }
  let configaggrid1 = ref({
    url: 'purchase/FixedScrap/getPage', //接口路径
    queryData: {
      deleteState: 0,
      auditState: 1,
      processedState: 0,
    },
    paginationShow: true, //分页是否显示
    invokeiIterface: true, //是否调用接口
    rowMultiSelectWithClick: false, //点击行是否多选
    column: tableColumns1,
    fileName: 'RetirementOfFixedAssets-2',
  })
  const refgridOption6 = ref<any>(null)
  let configaggrid6 = ref({
    url: 'purchase/phNofixedScrap/getPage', //接口路径
    queryData: {
      scrapCode: pageData.scrapCode,
      companyID: pageData.companyID,
      createName: pageData.scrapPerson,
      processedState: 0,
    },
    paginationShow: true, //分页是否显示
    invokeiIterface: true, //是否调用接口
    rowMultiSelectWithClick: false, //点击行是否多选
    column: tableColumns1,
    fileName: 'RetirementOfFixedAssets-6',
  })
  let configaggrid2 = ref({
    url: 'purchase/FixedScrap/getPage', //接口路径
    queryData: { deleteState: 0, processedState: 1 },
    paginationShow: true, //分页是否显示
    invokeiIterface: true, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns1,
    fileName: 'RetirementOfFixedAssets-3',
  })
  let tableColumns9: any = [
    {
      headerCheckboxSelection: true,
      checkboxSelection: true,
      width: 60,
      showDisabledCheckboxes: false,
      pinned: 'left',
    },
    {
      headerName: '报废单号',
      field: 'scrapCode',
      width: 250,
    },
    {
      headerName: '报废公司',
      field: 'companyName',
      width: 250,
    },
    {
      headerName: '报废时间',
      field: 'createTime',
      width: 250,
    },
    {
      headerName: '报废人',
      field: 'createName',
      width: 250,
    },
    {
      headerName: '处理状态',
      field: 'processedState',
      width: 250,
      cellRenderer: tagRender,
      cellRendererParams: {
        styleClass: (params: any) => {
          return params.processedState == 0
            ? 'warning'
            : params.processedState == 1
            ? 'success'
            : ''
        },
        text: (params: any) => {
          return params.processedState == 0 ? '待处理' : params.processedState == 1 ? '已处理' : ''
        },
        eltagSize: 0,
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '0'
            ? '待审核'
            : params.value == '1'
            ? '审核通过'
            : params.value == '2'
            ? '审核驳回'
            : ''
        },
      },
    },
  ]
  tableColumns9.push({
    headerName: '操作',
    field: 'ouihadpc',
    resizable: 'false',
    filter: false,
    sortable: 'false',
    width: 200,
    // lockPosition: 'right',
    pinned: 'right',
    cellRenderer: buttionRender,
    cellRendererParams: {
      buttonList: [
        {
          type: 'success',
          text: '详情',
          typeName: 'el-button',
          Callback: (data: any) => {
            for (let key in data) {
              query[key] = data[key]
            }
            goDetail(data)
          },
        },
      ],
      eltagSize: 0,
    },
  })
  const table4Ref = ref<any>(null)
  let configTable4 = ref({
    url: '', //接口路径
    queryData: {},
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns10,
    fileName: 'RetirementOfFixedAssets-10',
  })
  const goDetail = async (data: any) => {
    try {
      const res = await post({
        url: 'purchase/phNofixedScrap/getDetailList',
        data: {
          nofixedScrapId: data.id,
          processedState: '1',
        },
      })
      if (res.code == 200) {
        pageData.dialogFormVules1 = true
        nextTick(() => {
          table4Ref.value.setdataListIterface(res.data)
        })
      } else {
        ElMessage.error(res.message)
      }
    } catch (e) {
      console.log(e)
    }
  }
  let configTable3 = ref({
    url: 'purchase/phNofixedScrap/getPage', //接口路径
    queryData: {
      companyID: pageData.companyID1,
      processedState: '1',
      startTime: pageData.startDate,
      endTime: pageData.endDate,
    },
    paginationShow: true, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns9,
    fileName: 'RetirementOfFixedAssets-9',
  })
  // 表格列
  let tableColumns3: any = [
    {
      headerCheckboxSelection: true,
      checkboxSelection: true,
      width: 60,
      showDisabledCheckboxes: false,
      pinned: 'left',
    },
    // {
    //     headerName: '报废单号',
    //     field: 'scrapCode',
    //     width: 200,
    // },
    {
      headerName: '报废公司',
      field: 'companyName',
      width: 200,
    },
    {
      headerName: '机台名称',
      field: 'materialName',
      width: 200,
    },
    {
      headerName: '机台区域',
      field: 'district',
      width: 200,
    },
    {
      headerName: '报废方式',
      field: 'scrapWay',
      width: 200,
      // editable: true, // 覆盖了默认的不可编辑设置
      cellRenderer: selectRender,
      editable: true, // 覆盖了默认的不可编辑设置
      cellRendererParams: {
        // getRowData: function (params: any) {
        //     // 通过 params.node.data 获取整行数据
        //     // const rowData = params.node.data;
        //     // 使用整行数据执行其他操作
        //     console.log(params);
        // },
        changeData: (data: any) => {
          data.scrapMoney = 0
          const listData = JSON.parse(JSON.stringify(refgridOption3.value.getListData()))
          nextTick(() => {
            refgridOption3.value.setdataListIterface(listData)
          })
        },
        list: [
          { label: '有价值报废', value: '有价值报废' },
          { label: '无价值报废', value: '无价值报废' },
        ],
        key: 'scrapWay',
      },
    },
    {
      headerName: '报废金额',
      field: 'scrapMoney',
      width: 200,
      editable: (res: any) => {
        console.log(res)
        console.log(8888)
        return res.data.scrapWay == '有价值报废' ? true : false
      }, // 覆盖了默认的不可编辑设置
    },
    {
      headerName: '入厂时间',
      field: 'joinFactoryTime',
      width: 200,
    },
    {
      headerName: '报废时间',
      field: 'scrapTime',
      width: 200,
    },
    {
      headerName: '折旧时间',
      field: 'deprecitionTime',
      width: 200,
    },
    {
      headerName: '折旧差异',
      field: 'difference',
      width: 200,
    },
    {
      headerName: '建立人',
      field: 'createName',
      width: 200,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 200,
    },
    {
      headerName: '修改人',
      field: 'updateName',
      width: 200,
    },
    {
      headerName: '修改时间',
      field: 'updateTime',
      width: 200,
    },
    {
      headerName: '备注',
      field: 'remark',
      width: 200,
    },
    {
      headerName: '处理状态',
      field: 'processedState',
      width: 200,
      cellRenderer: tagRender,
      cellRendererParams: {
        styleClass: (params: any) => {
          return params.processedState == 0
            ? 'warning'
            : params.processedState == 1
            ? 'success'
            : ''
        },
        text: (params: any) => {
          return params.processedState == 0 ? '未处理' : params.processedState == 1 ? '已处理' : ''
        },
        eltagSize: 0,
      },
    },
  ]
  let configaggrid3 = ref({
    url: '', //接口路径
    queryData: {},
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: false, //点击行是否多选
    column: tableColumns3,
  })
  let configaggrid4 = ref({
    url: 'wms/ironwareStockInfo/getList', //接口路径
    queryData: {
      companyID: '',
      companyName: '',
      mechanicalCode: '',
      companyId: query.companyID,
      outDepartmentId: query.departmentID,
    },

    paginationShow: true, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns4,
    selectable: isRowSelectable,
    rowStyle: (rowNode: any) => {
      if (
        rowNode.data.machineState != 0 &&
        (rowNode.data.subCategory === '单面机' ||
          rowNode.data.subCategory === '双面机' ||
          rowNode.data.subCategory === '罗纹机')
      ) {
        return { background: 'lightgrey' }
      }
      return null
    },
  })
  let configaggrid5 = ref({
    url: 'purchase/phNofixedScrap/getList', //接口路径
    queryData: NoFixedAssets,
    paginationShow: true, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns5,
  })
  let TheyAreFixedAssetsAggrid = ref({
    url: '', //接口路径
    queryData: {},
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns4,
  })
  let NoFixedAssetsAggrid = ref({
    url: '', //接口路径
    queryData: {},
    paginationShow: false, //分页是否显示
    invokeiIterface: false, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns5,
  })
  const addWorkbench = () => {
    pageData.workbenchShowAdd = true
    lastSelectionList = []
    nextTick(() => {
      FixedAssetsgetList()
      selectFocus2()
    })
  }
  //删除机台
  const deleteWorkbench = () => {
    if (pageData.fixedAsset) {
      let selectedData = refgridTheyAreFixedAssetsAggrid.value.getSelectedRows()
      if (selectedData.length == 0) {
        ElMessage.warning('请勾选您要删除的单据')
        return
      }
      ElMessageBox.confirm('确认删除选中单据?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          refgridTheyAreFixedAssetsAggrid.value.applyTransaction({ remove: selectedData })
          ElMessage({
            type: 'success',
            message: '删除成功',
          })
        })
        .catch(() => {})
    }
    if (!pageData.fixedAsset) {
      let selectedData = refgridNoFixedAssets.value.getSelectedRows()
      if (selectedData.length == 0) {
        ElMessage.warning('请勾选您要删除的单据')
        return
      }
      ElMessageBox.confirm('确认删除选中单据?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          refgridNoFixedAssets.value.applyTransaction({ remove: selectedData })
          ElMessage({
            type: 'success',
            message: '删除成功',
          })
        })
        .catch(() => {})
    }
  }
  //机台保存
  const stockKeeping = () => {
    if (pageData.fixedAsset) {
      let arr3 = refgridOption4.value.getSelectedRows()
      arr3.forEach((r: any) => {
        r['joinMoney'] = r['price']
      })
      arr3.map((item: any) => {
        item.nofixedScrapId = item.id
        delete item.id
      })
      if (arr3.length == 0) {
        ElMessage.warning('请勾选您要选择的机台')
        return
      }
      let arr = refgridTheyAreFixedAssetsAggrid.value.getListData()
      for (const item of arr) {
        const found = arr3.find((elem: any) => elem.numberId === item.numberId)
        if (!found) {
          arr3.push(item)
        }
      }
      const newArr = arr3.map((item: any) => {
        if (item.hasOwnProperty('fixedScrapState')) {
          return {
            ...item,
            fixedScrapState: 1,
          }
        }
        return item
      })
      refgridTheyAreFixedAssetsAggrid.value.setdataListIterface([...newArr])
    }
    if (!pageData.fixedAsset) {
      let arr3 = refgridOption5.value.getSelectedRows()
      if (arr3.length == 0) {
        ElMessage.warning('请勾选您要选择的机台')
        return
      }
      arr3.map((item: any) => {
        item.nofixedScrapId = item.id
        delete item.id
      })
      let arr = refgridNoFixedAssets.value.getListData()
      for (const item of arr) {
        const found = arr3.find((elem: any) => elem.nofixedScrapId === item.nofixedScrapId)
        if (!found) {
          arr3.push(item)
        }
      }
      refgridNoFixedAssets.value.setdataListIterface([...arr3])
    }

    pageData.workbenchShowAdd = false
  }
  let cascaderRef = ref('')
  let configCascader = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '报废公司', //公司label
    sectorName: '报废部门', //部门label
    cascaderShow: '', //配置部门不显示
  })
  let configCascader4 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    corporateRquired: false, //公司是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '报废公司', //公司label
    cascaderShow: 'sector', //配置部门不显示
  })
  const changeCascader = (data: any) => {
    const { corporateId, corporateLabel, sectorLabel, sectorId } = data
    console.log(data)
    pageData.companyName = corporateLabel
    pageData.companyID = corporateId
    pageData.departmentName = sectorLabel
    pageData.departmentID = sectorId
  }
  const changeCascader4 = (data: any) => {
    const { corporateId, corporateLabel, sectorLabel, sectorId } = data
    console.log(data)
    pageData.companyName = corporateLabel
    pageData.companyID = corporateId
  }
  let configCascader1 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '报废公司', //公司label
    cascaderShow: 'sector', //配置部门不显示
  })
  const changeCascader1 = (data: any) => {
    const { corporateId, corporateLabel } = data
    console.log(data)
    pageData.companyName1 = corporateLabel
    pageData.companyID1 = corporateId
  }
  let form = reactive<any>({
    deleteState: 0,
  })
  const scrapMode = async () => {
    if (pageData.active1 == 1) {
      let arr = refgridOption3.value.getListData()
      refgridOption3.value.stopEditing()
      scrapDisposalData.value.list = arr
      arr[0].processedState = 1
      let stadey = arr.every((item: any) => {
        return item.scrapWay
      })
      if (stadey) {
        const params = {
          id: scrapDisposalData.value.id,
          list: arr,
        }
        try {
          pageData.loadingUp1 = true
          let { code, message } = await post({
            url: 'purchase/FixedScrap/setFixedScrap',
            data: params,
          })
          if (code == 200) {
            getList()
            ElMessage.success('报废处理成功')
            pageData.showAdd1 = false
            pageData.loadingUp1 = false
            return
          }
          ElMessage.error(message)
        } finally {
          pageData.loadingUp1 = false
        }
      } else {
        ElMessage.error('报废方式不能为空！')
      }
    } else {
      let arr = table2Ref.value.getListData()
      table2Ref.value.stopEditing()
      let stadey = arr.every((item: any) => {
        return item.scrapType
      })
      const selectedRows = table2Ref.value.getSelectedRows()
      if (selectedRows.length == 0) {
        ElMessage.error('请勾选您要保存的数据')
        return
      }
      selectedRows.forEach((item: any) => (item.processedState = 1))
      if (stadey) {
        try {
          pageData.loadingUp1 = true
          let { code, message } = await post({
            url: 'purchase/phNofixedScrap/updateDetail',
            data: selectedRows,
          })
          if (code == 200) {
            getList()
            ElMessage.success('报废处理成功')
            pageData.showAdd1 = false
            pageData.loadingUp1 = false
            return
          }
          ElMessage.error(message)
        } catch (e) {
          console.log(e)
        } finally {
          pageData.loadingUp1 = false
        }
      } else {
        ElMessage.error('报废方式不能为空！')
      }
    }
  }
  let lastSelectionList: any = []
  const selectionChange = (params: any) => {
    let SelectionList = refgridOption4.value.getSelectedRows()
    let checkRes = SelectionList.filter(
      (item: any) =>
        item.machineState != 0 &&
        (item.subCategory === '单面机' ||
          item.subCategory === '双面机' ||
          item.subCategory === '罗纹机')
    )
    if (checkRes.length > 0) {
      let str = checkRes.map((item: any) => item.numberId).join(',')
      ElMessage.error(`不允许勾选，固定资产编号${str}在机台设备维护内机台状态不是未启动`)
      params.api.forEachNode((node: any) => {
        const numberIdList = lastSelectionList.map((item: any) => item.numberId)
        if (numberIdList.includes(node.data.numberId)) {
          node.setSelected(true)
        } else {
          node.setSelected(false)
        }
      })
    }
    lastSelectionList = SelectionList
  }
  const newData = async (type: string, data: any) => {
    pageData.type = type

    if (type == '新增') {
      selectFocus()
      for (let key in query) {
        query[key] = ''
      }
      pageData.id = ''
      pageData.fixedAsset = true
      try {
        pageData.loadingUp = true
        let { code, message, data } = await post({
          url: 'purchase/FixedScrap/getScrapCode',
        })
        if (code == 200) {
          pageData.loadingUp = false
          query.scrapCode = data
          acquisitionCompany()
          return
        }
        ElMessage.error(message)
      } finally {
        pageData.loadingUp = false
      }
    }
    if (type == '修改') {
      // selectFocus()
      pageData.showAdd = true
      if (data.fixAssetStatus == 0) pageData.fixedAsset = false
      if (data.fixAssetStatus == 1) pageData.fixedAsset = true
      nextTick(() => {
        const { id, list, NoScrapList, companyID, companyName, departmentID, departmentName } = data
        let pam = {
          sectorId: departmentID,
          sectorLabel: departmentName,
          corporateId: companyID,
          corporateLabel: companyName,
        }
        pageData.id = id
        cascaderRef3.value?.parentComponent(pam)
        if (pageData.fixedAsset) {
          post({
            url: 'purchase/FixedScrapDetail/getList',
            data: {
              scrapID: id,
            },
          }).then(({ code, data }) => {
            if (code == 200) {
              refgridTheyAreFixedAssetsAggrid.value.setdataListIterface([...data])
            }
          })
          refgridNoFixedAssets.value.setdataListIterface([])
        }
        if (!pageData.fixedAsset) {
          refgridNoFixedAssets.value.setdataListIterface([...NoScrapList])
          refgridTheyAreFixedAssetsAggrid.value.setdataListIterface([])
        }
      })
    }
    if (type == '详情') {
      //固定资产的详情
      if (data.fixAssetStatus == 1) {
        post({
          url: 'purchase/FixedScrapDetail/getList',
          data: {
            scrapID: data.id,
          },
        }).then(({ code, data }) => {
          if (code == 200) {
            pageData.dialogFormVules = true
            pageData.dataListOP = data
          }
        })
        pageData.dataListTable = tableColumns4
      } else {
        post({
          url: 'purchase/phNofixedScrap/getDetailList',
          data: {
            nofixedScrapId: data.id,
          },
        }).then(({ code, data }) => {
          if (code == 200) {
            pageData.dialogFormVules = true
            nextTick(() => {
              table1Ref.value.setdataListIterface(data)
            })
          }
        })
      }
    }
  }

  let cascaderRef3: any = ref()
  let configCascader3 = ref<{}>({
    corporateWidth: '190px', //公司宽度
    sectorWidth: '190px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: true, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '公司', //公司label
    sectorName: '部门名称', //部门label
    cascaderShow: '', //配置部门不显示
    sectorNameLabelWidth: '78px',
    corporateNameLabelWidth: '78px',
  })
  const changeCascader3 = async (data: any) => {
    console.log(data)
    const { corporateId, corporateLabel, sectorLabel, sectorId } = data
    query.companyName = corporateLabel
    query.companyID = corporateId
    query.departmentName = sectorLabel
    query.departmentID = sectorId
  }

  const acquisitionCompany = async () => {
    try {
      pageData.loadingUp = true
      let { code, message, data } = await post({
        url: 'admin/acl/user/findUserToken',
      })
      if (code == 200) {
        const { firmId, firmName, departmentId, department } = data.data
        query.companyID = firmId
        query.companyName = firmName
        query.departmentID = departmentId
        query.departmentName = department
        pageData.showAdd = true
        nextTick(() => {
          cascaderRef3.value?.parentComponent({
            sectorId: departmentId,
            corporateId: firmId,
            corporateLabel: firmName,
            sectorLabel: department,
          })
          refgridTheyAreFixedAssetsAggrid.value.setdataListIterface([])
          refgridNoFixedAssets.value.setdataListIterface([])
        })
        pageData.loadingUp = false
        return
      }
      ElMessage.error(message)
    } finally {
      pageData.loadingUp = false
    }
  }
  const deleteData = () => {
    const selectedData = refgridOption.value.getSelectedRows()
    if (selectedData.length == 0) {
      ElMessage.warning('请勾选您要删除的单据')
      return
    }
    let condition = selectedData.every((item: any) => item.auditState == 1)
    if (condition) {
      ElMessage.warning('状态为审核通过不可删除!')
      return
    }
    ElMessageBox.confirm('确认删除选中单据?', '提示', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    })
      .then(async () => {
        try {
          pageData.loadingUp = true
          let arr: any
          arr = []
          selectedData.map((item: any) => {
            arr.push(item.id)
          })
          let { code, message } = await post({
            url: 'purchase/FixedScrap/delete',
            data: arr,
          })
          if (code == 200) {
            ElMessage.success('删除成功')
            pageData.loadingUp = false
            getList()
            return
          }
          ElMessage.error(message)
        } finally {
          pageData.loadingUp = false
        }
      })
      .catch(() => {})
  }
  const ruleFormRef = ref<any>()
  const confirmSave = () => {
    let arr3
    if (pageData.fixedAsset) {
      arr3 = refgridTheyAreFixedAssetsAggrid.value.getListData()
      if (arr3.length == 0) {
        ElMessage.warning('请勾选您要选择的机台')
        return
      }
    }
    if (!pageData.fixedAsset) {
      arr3 = refgridNoFixedAssets.value.getListData()
      if (arr3.length == 0) {
        ElMessage.warning('请勾选您要选择的机台')
        return
      }
    }
    let JTtips = ''
    let ZTtips = ''
    let tips = ''
    arr3.forEach((item: any) => {
      if (
        item.subCategory === '单面机' ||
        item.subCategory === '双面机' ||
        item.subCategory === '罗纹机'
      ) {
        if (JTtips.length > 0) {
          JTtips += ','
        }
        JTtips += JSON.stringify(item.numberId)
      } else if (item.subCategory === '针筒') {
        if (ZTtips.length > 0) {
          ZTtips += ','
        }
        ZTtips += JSON.stringify(item.numberId)
      }
    })
    if (JTtips.length > 0) {
      tips += `删除固定编号${JTtips}在机台设备维护内的资料，请谨慎操作！\n`
    }
    if (ZTtips.length > 0) {
      tips += `删除固定编号${ZTtips}在机台设备维护内的资料，请谨慎操作！\n`
    }
    if (tips.length > 0) {
      ElMessageBox.confirm(tips, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        save()
      })
    } else {
      save()
    }
  }
  const save = async () => {
    // return ruleFormRef.value.form.validate((valid: boolean) => {
    //   return valid
    // })
    if (pageData.fixedAsset) {
      let arr3 = refgridTheyAreFixedAssetsAggrid.value.getListData()
      // if (arr3.length == 0) {
      //   ElMessage.warning('请勾选您要选择的机台')
      //   return
      // }
      query.list = arr3
      query.fixAssetStatus = 1
    }
    if (!pageData.fixedAsset) {
      let arr3 = refgridNoFixedAssets.value.getListData()
      // if (arr3.length == 0) {
      //   ElMessage.warning('请勾选您要选择的机台')
      //   return
      // }
      query.list = arr3
      query.fixAssetStatus = 0
    }
    try {
      await ruleFormRef.value.validate()
      // 表单验证通过，执行保存逻辑
      if (pageData.type == '新增') {
        try {
          pageData.loadingUp = true
          let { code, message } = await post({
            url: 'purchase/FixedScrap/insert',
            data: query,
          })
          if (code == 200) {
            ElMessage.success('新增成功')
            pageData.loadingUp = false
            getList()
            pageData.showAdd = false
            return
          }
          ElMessage.error(message)
        } finally {
          pageData.loadingUp = false
        }
      }
      if (pageData.type == '修改') {
        let pam = query
        pam.id = pageData.id
        try {
          pageData.loadingUp = true
          let { code, message } = await post({
            url: 'purchase/FixedScrap/update',
            data: pam,
          })
          if (code == 200) {
            ElMessage.success('修改成功')
            pageData.loadingUp = false
            getList()
            pageData.showAdd = false
            return
          }
          ElMessage.error(message)
        } finally {
          pageData.loadingUp = false
        }
      }
    } catch (error) {
      // 表单验证失败，可以执行相应的错误处理逻辑
    }
  }
  const TurnDown = () => {
    const selectedData = refgridOption.value.getSelectedRows()
    if (selectedData.length == 0) {
      ElMessage.warning('请勾选您要驳回的单据')
      return
    }
    let condition = selectedData.every((item: any) => item.auditState == 1)
    if (condition) {
      ElMessage.warning('状态为审核通过不可驳回!')
      return
    }
    ElMessageBox.confirm('确认驳回选中单据?', '提示', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    })
      .then(async () => {
        try {
          pageData.loadingUp = true
          let arr: any = []
          selectedData.map((item: any) => {
            arr.push({
              id: item.id,
              auditState: 2,
            })
          })
          let { code, message } = await post({
            url: 'purchase/FixedScrap/setAudit',
            data: arr,
          })
          if (code == 200) {
            ElMessage.success('驳回成功')
            pageData.loadingUp = false
            getList()
            // refgridOption.value.setQuery(query)
            return
          }
          ElMessage.error(message)
        } finally {
          pageData.loadingUp = false
        }
      })
      .catch(() => {})
  }
  const audit = () => {
    const selectedData = refgridOption.value.getSelectedRows()
    if (selectedData.length == 0) {
      ElMessage.warning('请勾选您要审核的单据')
      return
    }
    let condition = selectedData.every((item: any) => item.auditState == 1)
    if (condition) {
      ElMessage.warning('状态为审核通过不可审核!')
      return
    }
    ElMessageBox.confirm('确认审核选中单据?', '提示', {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    })
      .then(async () => {
        try {
          pageData.loadingUp = true
          let arr: any
          arr = []
          selectedData.map((item: any) => {
            arr.push({
              id: item.id,
              auditState: 1,
            })
          })
          let { code, message } = await post({
            url: 'purchase/FixedScrap/setAudit',
            data: arr,
          })
          if (code == 200) {
            ElMessage.success('审核成功')
            pageData.loadingUp = false
            getList()
            return
          }
          ElMessage.error(message)
        } finally {
          pageData.loadingUp = false
        }
      })
      .catch(() => {})
  }
  const scrapDisposalData = ref<any>({})
  const scrapDisposal = async () => {
    if (pageData.active1 == 1) {
      const selectedData = refgridOption1.value.getSelectedRows()
      if (selectedData.length == 0) {
        ElMessage.warning('请勾选您要报废处理的单据')
        return
      }
      if (selectedData.length > 1) {
        ElMessage.warning('只能选择一条数据进行报废处理')
        return
      }
      pageData.showAdd1 = true
      console.log(selectedData)
      scrapDisposalData.value = selectedData[0]
      nextTick(() => {
        post({
          url: 'purchase/FixedScrapDetail/getList',
          data: {
            scrapID: scrapDisposalData.value.id,
          },
        }).then(({ code, data }) => {
          if (code == 200) {
            refgridOption3.value.setdataListIterface(data)
          }
        })
      })
    } else if (pageData.active1 == 2) {
      const selectedData = refgridOption6.value.getSelectedRows()
      if (selectedData.length == 0) {
        ElMessage.warning('请勾选您要报废处理的单据')
        return
      }
      if (selectedData.length > 1) {
        ElMessage.warning('只能选择一条数据进行报废处理')
        return
      }
      pageData.showAdd1 = true
      nextTick(() => {
        post({
          url: 'purchase/phNofixedScrap/getDetailList',
          data: {
            nofixedScrapId: selectedData[0].id,
            processedState: '0',
          },
        }).then(({ code, data }) => {
          if (code == 200) {
            nextTick(() => {
              table2Ref.value.setdataListIterface(data)
            })
          }
        })
      })
    }
  }
  const tabChange = (tab: any) => {
    if (tab == 2) {
      pageData.active1 = '1'
      pageData.active2 = ''
    } else if (tab == 3) {
      pageData.active2 = '1'
      pageData.active1 = ''
    } else {
      pageData.active1 = ''
      pageData.active2 = ''
    }
    emitter.emit('window-change')
    pageData.active = tab
    getList()
  }

  onMounted(() => {
    getList()
    selectFocus()
  })
  const getList = () => {
    if (pageData.active == '1') {
      let pam = {
        deleteState: 0,
        auditState: 0,
        processedState: 0,
      }
      nextTick(() => {
        refgridOption.value.setQuery(pam)
      })
    }
    if (pageData.active == '2') {
      if (pageData.active1 == '1') {
        let pam = { ...form }
        pam.scrapCode = pageData.scrapCode
        pam.scrapPerson = pageData.scrapPerson
        // pam.companyName = pageData.companyName
        pam.companyID = pageData.companyID
        pam.departmentName = pageData.departmentName
        pam.departmentID = pageData.departmentID
        pam.deleteState = 0
        pam.auditState = 1
        pam.processedState = 0
        nextTick(() => {
          refgridOption1.value.setQuery(pam)
        })
      } else if (pageData.active1 == '2') {
        let params = { ...form }
        params.scrapCode = pageData.scrapCode
        params.createName = pageData.scrapPerson
        params.companyID = pageData.companyID
        params.processedState = '0'
        nextTick(() => {
          refgridOption6.value.setQuery(params)
        })
      }
    }
    if (pageData.active == '3') {
      if (pageData.active2 == '1') {
        let pam = {
          deleteState: 0,
          processedState: 1,
          auditState: 1,
          companyName: pageData.companyName1,
          companyID: pageData.companyID1,
          startDate: pageData.startDate,
          endDate: pageData.endDate,
        }
        nextTick(() => {
          refgridOption2.value.setQuery(pam)
        })
      } else if (pageData.active2 == '2') {
        nextTick(() => {
          table3Ref.value.setQuery({
            companyID: pageData.companyID1,
            processedState: '1',
            startTime: pageData.startDate,
            endTime: pageData.endDate,
          })
        })
      }
    }
  }
  const seclectList = reactive<any>({
    factoryList: [],
    mechanicalNameList: [],
    mechanicalCodeList: [],
    districtList: [],
    //物料大类
    MaterialCategoryList: [],
    //物料小类
    MaterialsubclassList: [],
    //物料名称
    MaterialNameList: [],
    //物料编号
    MaterialNumberList: [],
    //规格
    SpecificationsList: [],
    //封装配置下拉框数据
    EncapsulateConfigurationDropDownData: [
      {
        id: 'factoryList',
        url: 'wms/ironwareStockInfo/getFieldValue',
        label: 'companyName',
        value: 'companyId',
        pam: { companyName: '' },
      },
      {
        id: 'mechanicalNameList',
        url: 'wms/ironwareStockInfo/getFieldValueTwo',
        label: 'materialName',
        value: 'materialName',
        pam: {
          materialName: '',
          filterMap: {
            outFirmId: query.companyID,
            outDepartmentId: query.departmentID,
            stockState: 1,
          },
        },
      },
      {
        id: 'mechanicalCodeList',
        url: 'wms/ironwareStockInfo/getFieldValueTwo',
        label: 'materialCode',
        value: 'materialCode',
        pam: {
          materialCode: '',
          filterMap: {
            outFirmId: query.companyID,
            outDepartmentId: query.departmentID,
            stockState: 1,
          },
        },
      },
      {
        id: 'districtList',
        url: 'wms/ironwareStockInfo/getFieldValue',
        label: 'district',
        value: 'district',
        pam: { district: '' },
      },
      {
        id: 'MaterialCategoryList',
        url: 'purchase/phNofixedScrap/getFieldValue',
        label: 'bigClassName',
        value: 'bigClassName',
        pam: { bigClassName: '' },
      },
      {
        id: 'MaterialsubclassList',
        url: 'purchase/phNofixedScrap/getFieldValue',
        label: 'subClassName',
        value: 'subClassName',
        pam: { subClassName: '' },
      },
      {
        id: 'MaterialNameList',
        url: 'purchase/phNofixedScrap/getFieldValue',
        label: 'materialName',
        value: 'materialName',
        pam: { materialName: '' },
      },
      {
        id: 'MaterialNumberList',
        url: 'purchase/phNofixedScrap/getFieldValue',
        label: 'materialCode',
        value: 'materialCode',
        pam: { materialCode: '' },
      },
      {
        id: 'SpecificationsList',
        url: 'purchase/phNofixedScrap/getFieldValue',
        label: 'specName',
        value: 'specName',
        pam: { specName: '' },
      },
    ],
  })
  //查询是固定资产类下拉框
  const selectFocus = async () => {
    seclectList.EncapsulateConfigurationDropDownData.map(async (item: any, index: any) => {
      if (index != 1 && index != 2) {
        try {
          pageData.loadingUp2 = true
          let res: any = await post({
            url: item.url,
            data: item.pam,
          })
          if (res.code == 200) {
            seclectList[item.id] = res.data.map((item1: any) => {
              return {
                value: item1[item.value],
                label: item1[item.label],
              }
            })
            pageData.loadingUp2 = false
            return
          }
          ElMessage.error(res.message)
        } finally {
          pageData.loadingUp2 = false
        }
      }
    })
  }
  const selectFocus2 = async () => {
    seclectList.EncapsulateConfigurationDropDownData.map(async (item: any, index: any) => {
      if (index == 1 || index == 2) {
        try {
          pageData.loadingUp2 = true
          let res: any = await post({
            url: item.url,
            data: item.pam,
          })
          if (res.code == 200) {
            seclectList[item.id] = res.data.map((item1: any) => {
              return {
                value: item1[item.value],
                label: item1[item.label],
              }
            })
            pageData.loadingUp2 = false
            return
          }
          ElMessage.error(res.message)
        } finally {
          pageData.loadingUp2 = false
        }
      }
    })
  }
  // const MaterialCategorSelect = async (bigClassName: any) => {
  //   if (!bigClassName) {
  //     query.subClassName = ''
  //     MaterialsubclassList.value = []
  //     return
  //   }
  //   MaterialsubclassFocus(bigClassName)
  // }
  // const selectV2 = async (data: any) => {
  //   if (!data) {
  //     query.district = ''
  //     query.mechanicalCode = ''
  //     query.joinFactoryTime = ''
  //     query.scrapTime = ''
  //     query.deprecitionTime = ''
  //     query.difference = ''
  //     query.upDeprecitionTime = ''
  //     query.mechanicalName = ''
  //     return
  //   }
  //   console.log(data)
  //   let pam = {
  //     mechanicalCode: '',
  //     mechanicalName: '',
  //   }
  //   repairmanList.value.map((item: any) => {
  //     if (item.mechanicalCode == data) {
  //       pam = {
  //         mechanicalCode: item.mechanicalCode,
  //         mechanicalName: item.mechanicalName,
  //       }
  //     }
  //   })
  //   query.mechanicalCode = pam.mechanicalCode
  //   try {
  //     pageData.loadingUp = true
  //     let { code, message, data } = await post({
  //       url: 'purchase/FixedInitialize/getList',
  //       data: pam,
  //     })
  //     if (code == 200) {
  //       const {
  //         district,
  //         mechanicalCode,
  //         scrapTime,
  //         deprecitionTime,
  //         difference,
  //         joinFactoryTime,
  //         upDeprecitionTime,
  //         mechanicalName,
  //       } = data
  //       query.district = district
  //       query.mechanicalCode = mechanicalCode
  //       query.joinFactoryTime = joinFactoryTime
  //       query.scrapTime = scrapTime
  //       query.deprecitionTime = deprecitionTime
  //       query.difference = difference
  //       query.upDeprecitionTime = upDeprecitionTime
  //       query.mechanicalName = mechanicalName

  //       pageData.loadingUp = false
  //       return
  //     }
  //     ElMessage.error(message)
  //   } finally {
  //     pageData.loadingUp = false
  //   }
  //   console.log(pam)
  // }
  // 是固定资产

  const FixedAssetsgetList = () => {
    seclectList.EncapsulateConfigurationDropDownData[1].pam.filterMap.companyId = query.companyID
    seclectList.EncapsulateConfigurationDropDownData[1].pam.filterMap.outDepartmentId =
      query.departmentID
    seclectList.EncapsulateConfigurationDropDownData[2].pam.filterMap.companyId = query.companyID
    seclectList.EncapsulateConfigurationDropDownData[2].pam.filterMap.outDepartmentId =
      query.departmentID
    TheyAreFixedAssets.companyId = query.companyID
    TheyAreFixedAssets.outDepartmentId = query.departmentID
    if (pageData.fixedAsset) refgridOption4.value.setQuery({ ...TheyAreFixedAssets, stockState: 1 })
    if (!pageData.fixedAsset) refgridOption5.value.setQuery(NoFixedAssets)
  }
</script>

<script lang="ts">
  export default defineComponent({
    name: 'RetirementOfFixedAssets',
  })
</script>
<style scoped>
  .contioner {
    height: 100%;
    background-color: #fff;
  }

  .contentPrint {
    width: 100%;
    display: flex;
    justify-content: space-between;

    color: #000 !important;
  }

  .printLeft {
    width: 56%;
  }

  .printTitle {
    font-size: 22px;
    font-weight: 700;
    margin-top: 20px;
  }

  .printRight {
    width: 43%;
    display: flex;
    justify-content: space-between;
    flex-flow: row wrap;
  }

  .ermPrint {
    display: flex;
    justify-content: center;
    /* flex-flow: column wrap; */
    align-items: center;
  }

  .erm {
    width: 160px;
    height: 50px;
    background: #999;
  }

  .formPrint {
    display: flex;
    justify-content: space-between;
    flex-flow: row wrap;
  }

  .ban {
    width: 50%;
    margin-bottom: 5px;
  }

  .quan {
    width: 100%;
    margin-bottom: 5px;
  }

  table {
    text-align: center;
    color: #000;
  }

  td {
    color: #000;
  }

  th {
    color: #000;
  }

  .tablePrint {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    flex-flow: row wrap;
  }

  .footerPrint {
    display: flex;
    justify-content: space-around;
    margin-top: 8px;
    color: #000;
  }

  .createTime {
    width: 100px;
  }

  .printw {
    width: 30%;
    margin-bottom: 5px;
  }

  :deep(.el-dialog__body) {
    color: #000;
  }

  .my-tool-bar {
    background: #fff;
    padding: 18px;
  }

  .c-header {
    background: #fff;
    padding: 15px 0 10px 0;
  }

  :deep(.el-input__inner) {
    color: #3b3a3a;
  }

  :deep(.el-input__wrapper) {
    box-shadow: 0 0 0 1px #474849 inset;
  }

  :deep(.el-form-item__label) {
    color: #202021;
  }

  :deep(.el-select-v2__wrapper) {
    border: 1px solid #474849;
  }

  :deep(.el-radio.is-bordered) {
    border: 1px solid #474849;
  }

  :deep(.arco-drawer-container) {
    z-index: 1000 !important;
  }

  .hengxian {
    height: 5px;
    border-bottom: 1px solid #cecece;
    margin-bottom: 22px;
  }

  .darCont {
    width: 100%;
    height: 100%;
  }

  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }

  :deep(.ag-header-group-text) {
    text-align: center;
  }

  :deep(.ag-header-group-cell-label, .ag-header-cell-label) {
    justify-content: center !important;
  }
</style>
